<?php 
$ser=$_SERVER['REMOTE_ADDR']; 
$database = "po";
$username = "admin";
$password = "dacavrei";
$connection = mysql_connect("localhost", $username, $password) 
or die ("Unable to connect to the DB Server!");
mysql_select_db($database)
or die ("Unable to select DB");
$addon="";
$user=0;
$pass=0;
$name=0;
$time=0; 
$query="SELECT * FROM kick WHERE ip = '".$ser."';";
$res=mysql_query($query);
$n=mysql_numrows($res);
$trykick=0;
if($n) $trykick=mysql_result($res,0,'try');
if($trykick==3) ;
else $trykick=0;
if($_POST['logout']){ 
	setcookie('user','',time()-3600);
	setcookie('pass','',time()-3600);
}  
else{ 
	if($_POST['2days'])
		$time=60*60*24*2;
}
if(isset($_POST['user']) && isset($_POST['pass']))
	if(!$trykick){
		$user=$_POST['user'];
		$pass=$_POST['pass'];
		$l=strlen($user);
		for($i=0;$i<$l;++$i)
			if($user[$i]=='\'' || $user[$i]=='\\')
				$user="";
		$l=strlen($pass);
		for($i=0;$i<$l;++$i)
			if($pass[$i]=='\'' || $pass[$i]=='\\')
				$pass="";
		$query="SELECT * FROM user WHERE user = '".$user."';";
		$res=mysql_query($query);
		$n=mysql_numrows($res);
		$ok=0;
		if($n)
			if(!strcmp(mysql_result($res,0,'pass'),$pass)){ 
				$name=mysql_result($res,0,'name');
				$rang=(int)mysql_result($res,0,'rang'); 
				if($time && $rang>2)
					$time=60*60*24*7;
					setcookie('user',$user,$time+time());
					setcookie('pass',$pass,$time+time());			
					$name=mysql_result($res,0,'name');
					$rang=(int)mysql_result($res,0,'rang'); 
					$ok=1;
			}
		if(!$ok){
			$user=0;
			$pass=0;
			$name=0;
			$ser=$_SERVER['REMOTE_ADDR']; 
			$query="SELECT ip,try,lt+0 FROM kick WHERE ip = '".$ser."';";
			$res=mysql_query($query);
			$n=mysql_numrows($res);
			if(!$n) { 
				$query="INSERT INTO kick VALUES('".$ser."',1,NOW());";
				mysql_query($query);
			}
			else{
				$lt=mysql_result($res,0,'lt+0');
				$query="SELECT NOW()+0;";
				$now2=mysql_result(mysql_query($query),0,'NOW()+0');  
				++$now2;
				--$now2;
				++$lt;
				--$lt;
				if($now2-$lt>60*10) {
					$query="UPDATE kick SET try = 1 WHERE ip ='".$ser."';";
					mysql_query($query);			
					$query="UPDATE kick SET lt = NOW() WHERE ip = '".$ser."';";
					mysql_query($query);
				}
				else{
					$try=(int)mysql_result($res,0,'try');
					++$try;		
					$query="UPDATE kick SET try = ".$try." WHERE ip ='".$ser."';";
					mysql_query($query);			
					$query="UPDATE kick SET lt = NOW() WHERE ip = '".$ser."';";
					mysql_query($query);
				}
			}
			$res=mysql_query("SELECT ip,try,lt+0 FROM kick WHERE ip ='".$ser."';");  
			echo '<center class="fs" style="color:red;">You have entered a wrong username or password for '.mysql_result($res,0,'try').' times</center><br>';   	 					  		  
		}
	}
	else{
		echo '<center class="fs" style="color:red">You have entered a wrong username or password for 3 times and got a temporary ban of 10 minutes.</center>';
	}
else 
	if(isset($_COOKIE['user']) && isset($_COOKIE['pass'])){
		$user=$_COOKIE['user'];
		$pass=$_COOKIE['pass'];
		$l=strlen($user);
		for($i=0;$i<$l;++$i)
			if($user[$i]=='\'' || $user[$i]=='\\')
				$user="";
		$l=strlen($pass);
		for($i=0;$i<$l;++$i)
			if($pass[$i]=='\'' || $pass[$i]=='\\')
				$pass="";
		$query="SELECT * FROM user WHERE user = '".$user."';";
		$res=mysql_query($query);
		$n=mysql_numrows($res);
		$ok=0;	
		if($n)
			if(!strcmp(mysql_result($res,0,'pass'),$pass)){
				$ok=1;
				$name=mysql_result($res,0,'name');
				$rang=mysql_result($res,0,'rang');
			}  	
		if(!$ok){
			$user=0;
			$pass=0;
			$name=0;
			setcookie('user',$user,time()+$time);
			setcookie('pass',$pass,$time+time()); 
			$ser=$_SERVER['REMOTE_ADDR']; 
			echo $ser;
			$query="SELECT ip,try,lt+0 FROM kick WHERE ip = '".$ser."';";
			$res=mysql_query($query);
			$n=mysql_numrows($res);
			if(!$n) { 
				$query="INSERT INTO kick VALUES('".$ser."',1,NOW());";
				mysql_query($query);
			}
			else{
				$lt=mysql_result($res,0,'lt+0');
				$query="SELECT NOW()+0;";
				$now2=mysql_result(mysql_query($query),0,'NOW()+0');  
				++$now2;
				--$now2;
				++$lt;
				--$lt;
				echo $now2." ".$lt." ".($now2-$lt);
				if($now2-$lt>60*10) {
					$query="UPDATE kick SET try = 1 WHERE ip ='".$ser."';";
					mysql_query($query);			
					$query="UPDATE kick SET lt = NOW() WHERE ip = '".$ser."';";
					echo $query;
				}
				else{
					$try=(int)mysql_result($res,0,'try');
					++$try;		
					$query="UPDATE kick SET try = ".$try." WHERE ip ='".$ser."';";
					mysql_query($query);			
					$query="UPDATE kick SET lt = NOW() WHERE ip = '".$ser."';";
					mysql_query($query);
				}
			}
			$res=mysql_query("SELECT ip,try,lt+0 FROM kick WHERE ip ='".$ser."';");  
			echo '<center class="fs" style="color:red;">You have entered a wrong username or password for '.mysql_result($res,0,'try').' times.asdasd</center><br>';   	 					  		  
		}
	}  
echo '<html>
<head>	 
<link rel="stylesheet" type="text/css" href="/main.css" />
<script type="text/javascript" src="/main.js"></script>
</head>
<body style="background-image: url(/Images/back.jpg);" onload="clear();">

<table id="principal" cellSpacing="0" cellPadding="0" width="1100px" align="center" border="0">
   <tr>
       <td background="/Images/stanga-sus.gif" width="7px" style="background-color: transparent"></td>
       <td background="/Images/orizontal.gif" height="7px" style="width:1086px" colspan="3"></td>
	   <td background="/Images/dreapta-sus.gif" width="7px" style="background-color: transparent"></td>
   </tr> 
   <tr>
       <td width="7px" background="/Images/vertical.gif" rowspan="4" colspan="1"></td>
	   <td width="1086px" vAlign="top" colspan="3"><img src="/Images/po.png" style="width:1086px"></td>
	   
	   
       <td width="7px" background="/Images/vertical.gif" rowspan="4" colspan="1"></td>
   </tr> 
   <tr>
   <td width="1086px" colspan="3">   <center> <ul>
	          <li><a href="/" ><img onmouseover="this.src=\'/Images/homeout.png\';" onmouseout="this.src=\'/Images/homeover.png\';" src="/Images/homeover.png">
	          </li>
			  <li><a href="/tasks.php" ><img onmouseover="this.src=\'/Images/tasksout.png\';" onmouseout="this.src=\'/Images/tasksover.png\';" src="/Images/tasksover.png">
	          </li>
			 ';
	if ($user)echo'
			  <li><a href="/submit.php" ><img onmouseover="this.src=\'/Images/submitout.png\';" onmouseout="this.src=\'/Images/submitover.png\';" src="/Images/submitover.png">
	          ';
	if (!$user)echo'</li>
			  <li><a href="/signup.php" ><img onmouseover="this.src=\'/Images/signupout.png\';" onmouseout="this.src=\'/Images/signupover.png\';" src="/Images/signupover.png">
	          </li>';
	echo'<li><a href="/status.php" ><img onmouseover="this.src=\'/Images/statusout.png\';" onmouseout="this.src=\'/Images/statusover.png\';" src="/Images/statusover.png">
	          </li>
			  <li><a href="/links.php" ><img onmouseover="this.src=\'/Images/linksout.png\';" onmouseout="this.src=\'/Images/linksover.png\';" src="/Images/linksover.png">
	          </li>
			  <li><a href="/forum/cgi-bin/yabb/YaBB.pl" ><img onmouseover="this.src=\'/Images/forumout.png\';" onmouseout="this.src=\'/Images/forumover.png\';" src="/Images/forumover.png">
	          </li>
			  <li><a href="http://programmingonlinero.blogspot.com/" ><img onmouseover="this.src=\'/Images/blogout.png\';" onmouseout="this.src=\'/Images/blogover.png\';" src="/Images/blogover.png">
	          </li>
	       </ul></center>
	   </td>
	   </tr>
   <tr>
   	   <td background="/Images/orizontal.gif" height="7px" width="1086px" colspan="3"></TD>
   </tr>	   
   <tr>
	   <td height="586px" valign="top" width="290px" >
	   <br><br> 
	   ';
	    
	if($user&&$pass&&$name)echo '<center class="fs">Welcome<br>'.$name.'<Br>
								<form method="POST" action="">
								<input type="submit" name="logout" value="Log Out" style="font-size:16px;font-weight:bold"></form></center>
								';
	else  echo'<form method="POST" action="">
	 <table>
	 <tr><td class="fs">Username</td><td><input type="text" name="user" id="user" style="height:32px;padding:1px;margin:1px;font-size:16px;" onblur="f();" onfocus="g();"></td></tr>
	 <tr><td class="fs">Password</td><td><input type="password" name="pass" id="pass" style="height:32px;padding:1px;margin:1px;font-size:16px;" onblur="f();" onfocus="g();"></td></tr>
	 <tr><td class="fs" colspan="2"><center>Keep me logged for 2 days<input type="checkbox" name="2days"></center></td></tr>
	 <td colspan="2"><center><input type="submit" value="Submit" style="font-size:16px;"></center></td></tr>
	 </table>
	 </form>
	 ';
	 
	
	   echo'</td>
	   <td width="7px" background="/Images/vertical.gif" ></td>  
	   <td width="776px" style="background:#000000;padding:8px;opacity:0.8;-moz-opacity:0.8;filter:alpha(opacity=80);" valign="top" >  
   <br><br>
   <center class="fs" style="font-size:30px;">Create New Task</center>
   <br><br>
   '; if(isset($_POST['task_name'])){
	$this_task[1]=$_POST['task_name'];
	$this_task[2]=$_POST['author'];
	$this_task[3]=$_POST['contest'];
	$this_task[4]=$_POST['time_limit'];
	$this_task[5]=$_POST['mem_limit'];
	$this_task[6]=$_POST['s_limit'];
	$this_task[7]=$_POST['basic']+$_POST['C_DJGPP']*2+$_POST['C++_DJGPP']*4+$_POST['C_Borland']*8+$_POST['C++_Borland']*16+$_POST['C_Mingw']*32+
				  $_POST['C++_Mingw']*64+$_POST['C#']*128+$_POST['gcd']*256+$_POST['dmd']*512+$_POST['Java']*1024+$_POST['Nemerle']*2048+
				  $_POST['GPC']*4096+$_POST['FPC']*8192+$_POST['BPC']*16384+$_POST['ptx']*32768;
	}
	/*echo '<span style="color:white;" >Ai trimis numarul ';	echo $this_task[1];
															echo $this_task[2];
															echo $this_task[3];
															echo $this_task[4];
															echo $this_task[5];
															echo $this_task[6];
															echo $this_task[7];*/
   echo '
   <form method="POST" action="">
   
   <span style="color:white;" ><h3>
			Task Name
   <input type="text" name="task_name"></h3><p>
   
   <span style="color:white;" ><h3>
			Author
   <input type="text" name="author"></h3><p>
   
   <span style="color:white;" ><h3>
			Contest
   <input type="text" name="contest"></h3><p>
   
   <span style="color:white;" ><h3>
			Time Limit
   <input type="text" name="time_limit"></h3><p>
   
   <span style="color:white;" ><h3>
			Memory Limit
   <input type="text" name="mem_limit"></h3><p>
   
   <span style="color:white;" ><h3>
			Contest
   <input type="text" name="s_limit"></h3><p>
   
   <span style="color:white;" ><h3>
			Languages<p></h3>
						Basic<input type="checkbox" value="basic" checked="true" name="basic"><br>
						C (Djgpp)<input type="checkbox" value="C_DJGPP" checked="true" name="C_DJGPP"><br>
						C++ (Djgpp)<input type="checkbox" value="C++_DJGPP" checked="true" name="C++_DJGPP"><br>
						C (Borland)<input type="checkbox" value="C_Borland" checked="true" name="C_Borland"><br>
						C (Borland)<input type="checkbox" value="C++_Borland" checked="true" name="C++_Borland"><br>
						C (Mingw)<input type="checkbox" value="C_Mingw" checked="true" name="C_Mingw"><br>
						C++ (Mingw)<input type="checkbox" value="C++_Mingw" checked="true" name="C++_Mingw"><br>
						C# (Mono)<input type="checkbox" value="C#" checked="true" name="C#"><br>
						D (gcd)<input type="checkbox" value="gcd" checked="true" name="gcd"><br>
						D (dmd)<input type="checkbox" value="dmd" checked="true" name="dmd"><br>
						Java<input type="checkbox" value="Java" checked="true" name="Java"><br>
						Nemerle<input type="checkbox" value="Nemerle" checked="true" name="Nemerle"><br>
						Pascal (gpc) <input type="checkbox" value="GPC" checked="true" name="GPC"><br>
						Pascal (fpc) <input type="checkbox" value="FPC" checked="true" name="FPC"><br>
						Pascal (borland) <input type="checkbox" value="BPC" checked="true" name="BPC"><br>
						Pure text <input type="checkbox" value=ptx" checked="true" name="ptx"><br>
						
   <br>
   <input type="submit" value="Submit">
   </form>
   <tr>
       <td background="/Images/stanga-jos.gif" width="7px" style="background-color: transparent;"></td>
       <td background="/Images/orizontal.gif" height="7px" width="976px" colspan="3"></td>
	   <td background="/Images/dreapta-jos.gif" width="7px" style="background-color: transparent"></td>
   </tr> 
</table>
</center>
</body>
</html>';

 ?>
